<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function success($data = [], $statusCode = 200)
    {
        if (is_array($data) || is_object($data))
            return response()
                ->json($data, $statusCode);
        else
            return response($data, $statusCode);
    }

    public function error($code = 1, $msg = '', $statusCode = 400, $data = [], $debug = [])
    {
        return $this::result($code, $msg, $statusCode, $data, $debug);
    }

    static function result($code = 1, $msg = '', $statusCode = 400, $data = [], $debug = [])
    {
        return response()->json([
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
            'debug' => $debug
        ], $statusCode);
    }
}
